package cn.imvc.app.controllers.goods;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.entities.GoodsSpec;
import cn.imvc.app.entities.GoodsSpecValue;
import cn.imvc.app.models.GoodsSpecModel;
import cn.imvc.app.models.GoodsSpecValueModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class GoodsSpecValueControllerImpl implements GoodsSpecValueController {

	@Autowired
	GoodsSpecValueModel goodsSpecValueModel;
	@Autowired
	GoodsSpecModel goodsSpecModel;
	
	private String goodsSpecId;
	public Page<GoodsSpecValue> page;
	public int id;
	public int[] ids;
	public GoodsSpecValue goodsSpecValue;
	public GoodsSpec goodsSpec;
	public ViewRequest viewRequest;
	public List<GoodsSpecValue> goodsSpecValues;
	
	public void setGoodsSpecId(String goodsSpecId) {
		this.goodsSpecId = goodsSpecId;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}
	
	public void setGoodsSpec(GoodsSpec goodsSpec) {
		this.goodsSpec = goodsSpec;
	}
	
	public void setGoodsSpecValue(GoodsSpecValue goodsSpecValue) {
		this.goodsSpecValue = goodsSpecValue;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public void setIds(int[] ids) {
		this.ids = ids;
	}
	
	public String search() {
		// TODO Auto-generated method stub
		return null;
	}

	public String index() {
		Map<String, String> searchMap = new HashMap<String, String>();
		searchMap.put("goodsSpecId_eq_string", goodsSpecId);
		viewRequest = new ViewRequest();
		viewRequest.setParams(searchMap);
		page=goodsSpecValueModel.find(viewRequest);
		//查询goodsSpec对象，防止没有值时，找不到类型对象
		goodsSpec = goodsSpecModel.get(Integer.valueOf(goodsSpecId));
		return "goodsSpecValue/index";
	}

	public String show() {
		// TODO Auto-generated method stub
		return null;
	}

	public String editNew() {
		goodsSpecValue = new GoodsSpecValue();
		goodsSpec = goodsSpecModel.get(goodsSpec.getId());
		goodsSpecValue.setGoodsSpec(goodsSpec);
		return "goodsSpecValue/edit";
	}

	public String create() {
		goodsSpecValueModel.save(goodsSpecValue);
		return Render.json(new DialogBean("200", "创建成功","goodsSpecValue_index", "closeCurrent"));
	}

	public String edit() {
		goodsSpecValue = goodsSpecValueModel.get(id);
		return "goodsSpecValue/edit";
	}

	public String update() {
		goodsSpecValueModel.update(goodsSpecValue);
		return Render.json(new DialogBean("200", "修改成功","goodsSpecValue_index", "closeCurrent"));
	}

	public String destroy() {
		goodsSpecValueModel.delete(id);
		return Render.json(new DialogBean("200", "删除成功","goodsSpecValue_index"));
	}

	public String destroyBatch() {
		goodsSpecValueModel.deleteBatch(ids);
		return Render.json(new DialogBean("200", "删除成功","goodsSpecValue_index"));
	}

	public String dialog(){
		goodsSpec = new GoodsSpec();
		goodsSpec.setId(Integer.valueOf(goodsSpecId));
		goodsSpecValues = goodsSpecValueModel.findBygoodsSpec(goodsSpec);
		return "goodsSpecValue/dialog";
    }
}
